package sim.core;

import java.awt.*;
import java.awt.geom.*;

import sim.util.*;


/**
 * This class is the base class for the creation of more specific messages.
 * 
 * 
 * @author smd
 */

@SuppressWarnings("serial")
abstract public class Message implements EncodedMessage {
	
	protected boolean visible ;
	
	public Color color = Color.DARK_GRAY ;

	protected Message() {
		this( false, Color.gray ) ;
	}
	
	protected Message( boolean visible, Color color ) {
		this.color = color ;
		this.visible = visible ;
	}
	/**
	 * This method sets the color used for this message when message traffic is drawn in the simulator.
	 * @param color New color to be used.
	 */
	public void setColor( Color color ) {
		this.color = color ;
	}
	
	/**
	 * This method returns the color used to render this message in the simulator.
	 * @return the color used to render this message in the simulator.
	 */
	public Color getColor() {
		return color ;
	}
	
	public Message decode() {
		return this ;
	}

	public EncodedMessage encode() {
		return this ;
	}

	public int length() {
		return 0 ;
	}
	
    public boolean isVisible() {
    	return visible ;
    }

	/**
	 * This method has to be overridden in all message sub-types, derived from this class.
	 * 
	 * @param src - Source of the message.
	 * @param handler - Handler of the message.
	 */
	public void deliverTo( EndPoint src, MessageHandler handler ) {
		throw new RuntimeException("deliverTo() not overridden... in: " + this.getClass() ) ;
	}
	
	/**
	 * This method has to be overridden in all message sub-types, derived from this class.
	 * 
	 * @param src - Source of the message.
	 * @param handler - Handler of the message.
	 */
	public void deliverTo( TcpChannel ch, MessageHandler handler ) {
		throw new RuntimeException("deliverTo() not overridden... in: " + this.getClass() ) ;
	}
	
	public void display( EndPoint src, EndPoint dst, Graphics2D gs ) {
		gs.setColor( color ) ;
		XY a = src.pos, b = dst.pos ;
	    gs.draw( new Line2D.Double( a.x, a.y, b.x, b.y ) ) ;
	}
}
